<%@page import="qldc.pm.tiensu.searchcontainer.YeuCauTrichLucSearchTerms"%>
<%@page import="qldc.pm.tiensu.searchcontainer.YeuCauTrichLucDisplayTerms"%>
<%@page import="qldc.pm.tiensu.searchcontainer.YeuCauTrichLucSearch"%>
<%@page import="qldc.pm.tiensu.constants.TrangThaiTrichLucEnum"%>
<%@page import="qldc.pm.tiensu.service.YeuCauTrichLucLocalServiceUtil"%>
<%@page import="qldc.pm.tiensu.model.YeuCauTrichLuc"%>
<%@page import="com.liferay.portal.kernel.util.Validator"%>
<%@page import="com.liferay.portal.kernel.util.Constants"%>
<%@page import="qldc.pm.qtht.dmdc.service.TinhLocalServiceUtil"%>
<%@page import="qldc.pm.qtht.dmdc.model.Tinh"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Date"%>
<%@page import="com.liferay.portal.kernel.util.StringPool"%>
<%@page import="java.text.SimpleDateFormat"%>

<%@include file="../../init.jsp"%>

<%
	PortletURL portletURL = renderResponse.createRenderURL();
	portletURL.setParameter("mvcPath", "/html/view.jsp");
	portletURL.setParameter("chonChucNangItem",TienSuConstants.DS_BKTT);
	portletURL.setParameter("loaiBKTK",TienSuConstants.DS_TRICH_LUC);
	portletURL.setParameter("tabs1",TienSuConstants.DS_TRICH_LUC);

	PortletURL thoatUrl =  renderResponse.createRenderURL();
	thoatUrl.setParameter("mvcPath", "/html/view.jsp");
	thoatUrl.setParameter("chonChucNangItem",TienSuConstants.BAO_CAO_THONG_KE);
	String pathThemeImages = themeDisplay.getPathThemeImages();
	
%>

<portlet:resourceURL var="loadQuanHuyen" id="loadQuanHuyen">
	<portlet:param name="tinhIdSelected" value="{0}" />
</portlet:resourceURL>

<portlet:resourceURL var="loadPhuongXa" id="loadPhuongXa">
	<portlet:param name="quanHuyenIdSelected" value="{0}" />
</portlet:resourceURL>


<script type="text/javascript">
var NhapNgay = (function() {
	function NhapNgay() {}
	/*
	 * 
	 */
	 NhapNgay.prototype.initCalendars = function() {
			$("#<portlet:namespace/>tuNgayTaoTrichLuc").datepicker({
				showOn: "both",
				buttonImage: "<%=pathThemeImages%>/common/calendar.png",
					buttonImageOnly : true,
					buttonText : "<liferay-ui:message key="tuNgayPhamToi" />",
					dateFormat : "dd/mm/yy",
					onClose: function( selectedDate ) {
						 $("#<portlet:namespace/>denNgayTaoTrichLuc").datepicker( "option", "minDate", selectedDate );
						 }
				});
			$("#<portlet:namespace/>denNgayTaoTrichLuc").datepicker({
				showOn: "both",
				buttonImage: "<%=pathThemeImages%>/common/calendar.png",
					buttonImageOnly : true,
					buttonText : "<liferay-ui:message key="denNgayPhamToi" />",
					dateFormat : "dd/mm/yy",
					onClose: function( selectedDate ) {
						 $("#<portlet:namespace/>tuNgayTaoTrichLuc").datepicker( "option", "maxDate", selectedDate );
						 }
				});

		};

		return NhapNgay;
	})();

	$(function() {
		var dom = new NhapNgay();

		dom.initCalendars();
	});
</script>

<portlet:actionURL var="inDanhSachTrichLucURL">
	<portlet:param name="<%=TienSuConstants.ACTION_HANDLER_PARAM %>" value="<%=TienSuConstants.REPORT_ACTION %>"/>
	<portlet:param name="<%=Constants.ACTION %>" value="inReportDSHoSoTrichLuc"/>
	<portlet:param name="redirect" value="<%=portletURL.toString() %>"/>
</portlet:actionURL>
<div  class="main-Content" >

	
	<form id="<portlet:namespace />frm" action="<%=inDanhSachTrichLucURL.toString() %>"  method="POST" target="_blank">
			<%
			SimpleDateFormat sdf = new SimpleDateFormat(TienSuConstants.DATE_PATTERN);
			YeuCauTrichLucSearch yeuCauTrichLucSearch = new YeuCauTrichLucSearch(renderRequest,
					portletURL);
			YeuCauTrichLucDisplayTerms displayTerms = (YeuCauTrichLucDisplayTerms) yeuCauTrichLucSearch
					.getDisplayTerms();
			YeuCauTrichLucSearchTerms searchTerms = (YeuCauTrichLucSearchTerms) yeuCauTrichLucSearch
					.getSearchTerms();
			int sttDoiTuong = yeuCauTrichLucSearch.getDelta() * (yeuCauTrichLucSearch.getCur() - 1);
			long noiThuongTruTinhIdSelected = searchTerms.getTinhId();
			long noiThuongTruQuanHuyenIdSelected = searchTerms.getQuanHuyenId();
			long noiThuongTruPhuongXaIdSelected = searchTerms.getPhuongXaId();
			int totalRow = YeuCauTrichLucLocalServiceUtil.countByCQ_NguoiThucHienTaoTrichLuc_ThoiGian_VungDiaLy					
					(searchTerms.getCoQuanNguoiYeuCauTrichLuc(),searchTerms.getNguoiTaoTrichLuc(),
							searchTerms.getTinhId(), searchTerms.getQuanHuyenId(),searchTerms.getPhuongXaId(),
							searchTerms.getTuNgayTaoTrichLuc(),
							searchTerms.getDenNgayTaoTrichLuc());	
		
		%>
		<table class="gridnormal"  style="padding-top: 10px;padding-left: 10px">			
			<tr>
				<td class="aui-w20"><liferay-ui:message key="vung-dia-ly" /></td>

				<td colspan="3" class="aui-w80" ><select class="display-inline" style="width: 30%" name="<portlet:namespace/><%=YeuCauTrichLucDisplayTerms.TINH_ID %>" id="<portlet:namespace/>noiThuongTruTinhId"
					onchange="loadQuanHuyen('<portlet:namespace />noiThuongTruTinhId', '<portlet:namespace />noiThuongTruQuanHuyenId', '<portlet:namespace />noiThuongTruPhuongXaId', '<%=loadQuanHuyen.toString()%>','<%=noiThuongTruQuanHuyenIdSelected%>');">
						<option value="0"><liferay-ui:message key="chon-tinh" /></option>
						<%
							List<Tinh> tinhs = TinhLocalServiceUtil.findAll();

							for (Tinh tinh : tinhs) {
						%>
						<option value="<%=tinh.getTinhId()%>" <%=(noiThuongTruTinhIdSelected == tinh.getTinhId() || tinh.getLaMacDinh()) ? "selected=selected"
						: StringPool.BLANK%>><%=tinh.getTenTinh()%></option>
						<%
							}
						%>
				</select>
				 <select class="display-inline" style="width: 30%" name="<portlet:namespace/><%=YeuCauTrichLucDisplayTerms.QUAN_HUYEN_ID %>" id="<portlet:namespace/>noiThuongTruQuanHuyenId" onchange="loadPhuongXa('<portlet:namespace/>noiThuongTruQuanHuyenId', '<portlet:namespace/>noiThuongTruPhuongXaId', '<%=loadPhuongXa.toString()%>', '<%=noiThuongTruPhuongXaIdSelected%>');">
				 	<option value="0"><liferay-ui:message key="chon-quan-huyen" /></option>
				 
				 </select>

				<select class="display-inline" style="width: 30%" name="<portlet:namespace/><%=YeuCauTrichLucDisplayTerms.PHUONG_XA_ID %>" id="<portlet:namespace/>noiThuongTruPhuongXaId">
						<option value="0"><liferay-ui:message key="chon-phuong-xa" /></option>				
				</select>
				
				</td>
				
			</tr>
			<tr>
				<td class="txtlabel aui-w20"><liferay-ui:message key="ngay-tao-trich-luc-tu" /></td>
				<td colspan="3" class="aui-w80 ip-datepicker"><input type="text" id="<portlet:namespace/>tuNgayTaoTrichLuc" name="<portlet:namespace/><%=YeuCauTrichLucDisplayTerms.TU_NGAY_TAO_TRICH_LUC %>" value="<%=Validator.isNotNull(searchTerms.getTuNgayTaoTrichLuc()) ? sdf.format(searchTerms.getTuNgayTaoTrichLuc()):""%>" />
				&nbsp;&nbsp;<liferay-ui:message key="den-ngay" />
				&nbsp;&nbsp;<input type="text" id="<portlet:namespace/>denNgayTaoTrichLuc" name="<portlet:namespace/><%=YeuCauTrichLucDisplayTerms.DEN_NGAY_TAO_TRICH_LUC %>"  value="<%=Validator.isNotNull(searchTerms.getDenNgayTaoTrichLuc()) ? sdf.format(searchTerms.getDenNgayTaoTrichLuc()):""%>" />
				</td>
				
			</tr>
			<tr>
				<td class="txtlabel aui-w20"><liferay-ui:message key="co-quan-yeu-cau-trich-luc" /></td>
				<td class="aui-w30"><input type="text" id="<portlet:namespace/>coQuanYeuCauTrichLuc" value="<%=searchTerms.getCoQuanNguoiYeuCauTrichLuc() %>" name="<portlet:namespace/><%=YeuCauTrichLucDisplayTerms.CO_QUAN_NGUOI_YEU_CAU_TRICH_LUC %>" />
				
				</td>
				<td class="txtlabel aui-w20"><liferay-ui:message key="nguoi-thuc-hien-tao-trich-luc" /></td>
				<td class="aui-w30"><input type="text" style="width: 76%;" id="<portlet:namespace/>nguoiThucHienTrichLuc" value="<%=searchTerms.getNguoiTaoTrichLuc()%>" name="<portlet:namespace/><%=YeuCauTrichLucDisplayTerms.NGUOI_TAO_TRICH_LUC %>" />
				
				</td>
				
			</tr>
			<tr>
			<td></td>
			<td colspan="3">
			<div align="left">
				<input type=button onclick="timDanhSach();"  id="<portlet:namespace/>Tim"  class="btn btn-primary" name="<portlet:namespace/>Tim" value="<liferay-ui:message key="tim-kiem" />" /> 
			
				<input type=button onclick="taoBaoCao();" <%=totalRow == 0?"disabled='disabled'":"" %>  id="<portlet:namespace/>BaoCao"  class="btn btn-primary" name="<portlet:namespace/>BaoCao" value="<liferay-ui:message key="xuat-bao-cao" />" /> 
					 
				<input type=button class="btn"  name="<portlet:namespace/>thoat" value="<liferay-ui:message key="tro-ve" />"  onclick="window.location = '<%=thoatUrl.toString() %>';" />
			</div>
			</td>
			
			</tr>
		</table>
	</form>

<%
	if (searchTerms.getTinhId() > 0){
	%>
<liferay-ui:search-container  emptyResultsMessage="no-web-content-were-found"  searchContainer="<%=yeuCauTrichLucSearch %>">
	<liferay-ui:search-container-results>
		<%
			System.out.println("searchTerms.getQuanHuyenId() "+searchTerms.getQuanHuyenId());
			results = 
			YeuCauTrichLucLocalServiceUtil.findByCQ_NguoiThucHienTaoTrichLuc_ThoiGian_VungDiaLy(
					searchTerms.getCoQuanNguoiYeuCauTrichLuc(),searchTerms.getNguoiTaoTrichLuc(),
					searchTerms.getTinhId(), searchTerms.getQuanHuyenId(),searchTerms.getPhuongXaId(),
					searchTerms.getTuNgayTaoTrichLuc(),
					searchTerms.getDenNgayTaoTrichLuc(), searchContainer.getStart(),
							searchContainer.getEnd(), searchContainer.getOrderByComparator());

			total = totalRow;
			
		
			pageContext.setAttribute("results", results);
			pageContext.setAttribute("total", total);
		%>
	</liferay-ui:search-container-results>
	
	<%
		int start = yeuCauTrichLucSearch.getDelta() * (yeuCauTrichLucSearch.getCur() - 1);
	%>
	
	<liferay-ui:search-container-row className="qldc.pm.tiensu.dto.YeuCauTrichLucDTO" keyProperty="yeuCauTrichLucId" modelVar="yeuCauTrichLuc">

		<liferay-ui:search-container-column-text cssClass="aui-w3 txt-center" name="stt" value="<%=String.valueOf(++start) %>" />
		<liferay-ui:search-container-column-text cssClass="aui-w10 " name="ma-yeu-cau-trich-luc" property="maYeuCauTrichLuc" />		
		<liferay-ui:search-container-column-text cssClass="aui-w8" name="ngay-lap-trich-luc">
		<%=Validator.isNotNull(yeuCauTrichLuc.getNgayLapYeuCauTrichLuc()) ? sdf.format(yeuCauTrichLuc.getNgayLapYeuCauTrichLuc()) :""%>
		</liferay-ui:search-container-column-text>
		<liferay-ui:search-container-column-text cssClass="aui-w10" name="co-quan-nguoi-yeu-cau-trich-luc" property="coQuanYeuCauTrichLuc" />		
		<%-- <liferay-ui:search-container-column-text cssClass="aui-w8"  name="ngay-de-nghi-tra-trich-luc">		
		<%=Validator.isNotNull(yeuCauTrichLuc.getNgayYeuCauTraTrichLuc()) ? sdf.format(yeuCauTrichLuc.getNgayYeuCauTraTrichLuc()) :""%>
		</liferay-ui:search-container-column-text> --%>
		<liferay-ui:search-container-column-text cssClass="aui-w10 " name="nguoi-thuc-hien-tao-trich-luc" value="<%=yeuCauTrichLuc.getCanBoLapYeuCauTrichLuc() %>"/>
		<liferay-ui:search-container-column-text  name="noi-lap-trich-luc" value="<%=yeuCauTrichLuc.getDiaChi() %>"/>
		<liferay-ui:search-container-column-text cssClass="aui-w11" name="trang-thai">
		<liferay-ui:message key="<%=TrangThaiTrichLucEnum.getKey(yeuCauTrichLuc.getTrangThaiHoSo()? TrangThaiTrichLucEnum.DA_TRICH_LUC.getValue():TrangThaiTrichLucEnum.CHUA_TRICH_LUC.getValue())	 %>" /> 
		</liferay-ui:search-container-column-text> 
	<%-- 
		<liferay-ui:search-container-column-text cssClass="aui-w5 " name="stt" value="<%=String.valueOf(++start) %>" />
		<liferay-ui:search-container-column-text cssClass="aui-w10 " name="so-dinh-danh-ca-nhan" property="soDinhDanhCaNhan" />		
		<liferay-ui:search-container-column-text cssClass="aui-w13" name="ho-va-ten" property="hoTen" />
		<liferay-ui:search-container-column-text cssClass="aui-w8" name="ngay-sinh">
		<%=Validator.isNotNull(xoaAnTich.getNgaySinh()) ? dateFormat.format(xoaAnTich.getNgaySinh()) :""%>
		</liferay-ui:search-container-column-text>
		<liferay-ui:search-container-column-text cssClass="aui-w8"  name="so-cmnd" property="soCMND" />		
		<liferay-ui:search-container-column-text  name="dia-chi-thuong-tru" property="diaChi" />
		<liferay-ui:search-container-column-text cssClass="txt-center aui-w10"  name="so-lan-pham-toi" property="soLanPhamToi" />
		<liferay-ui:search-container-column-text cssClass="aui-w8" name="ngay-xoa-an-tich">
		<%=Validator.isNotNull(xoaAnTich.getNgayXoaAnTich()) ? dateFormat.format(xoaAnTich.getNgayXoaAnTich()) :""%>
		</liferay-ui:search-container-column-text> --%>
		
	</liferay-ui:search-container-row>

	<liferay-ui:search-iterator searchContainer="<%=yeuCauTrichLucSearch %>" />
</liferay-ui:search-container>
<%

	} else {
		%>
		<h5><liferay-ui:message key="vui-long-chon-tieu-chi-lap-bao-cao" /></h5>
	<%}
%>
</div>
<script type="text/javascript">
$(function() {
	 loadQuanHuyen('<portlet:namespace />noiThuongTruTinhId', '<portlet:namespace />noiThuongTruQuanHuyenId', '<portlet:namespace />noiThuongTruPhuongXaId', '<%=loadQuanHuyen.toString() %>','<%=noiThuongTruQuanHuyenIdSelected %>');
	 loadPhuongXa('<portlet:namespace/>noiThuongTruQuanHuyenId', '<portlet:namespace/>noiThuongTruPhuongXaId', '<%=loadPhuongXa.toString() %>', '<%=noiThuongTruPhuongXaIdSelected %>');
});

function timDanhSach(){
		$('#<portlet:namespace/>frm').removeAttr("target");
		$('#<portlet:namespace/>frm').removeAttr("action");
		$('#<portlet:namespace/>cmd').val('<%=TienSuConstants.TIM%>');
		$("#<portlet:namespace/>frm").attr('onsubmit', 'return true;');
		$("#<portlet:namespace/>frm").submit(); 
		
};
function taoBaoCao(){

		 $('#<portlet:namespace/>cmd').val('<%=TienSuConstants.IN%>');
			$("#<portlet:namespace/>frm").attr('target', '_blank');
			$("#<portlet:namespace/>frm").submit();
	 
	
};
</script>

